home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / interapplication comm / folder watching / fw receiver / utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.5 KB  |  175 lines

  1. /*
  2.     File:        Utilities.c
  3.  
  4.     Contains:    General utility routines
  5.  
  6.     Written by: Chris White    
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/21/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 12/18/95    CW                First release
  21.                 
  22.  
  23. */
  24.  
  25. #pragma segment Core
  26.  
  27.  
  28.  
  29. // System Includes
  30.  
  31. #ifndef __TYPES__
  32.     #include <Types.h>
  33. #endif
  34.  
  35. #ifndef __TEXTUTILS__
  36.     #include <TextUtils.h>
  37. #endif
  38.  
  39. #ifndef __DIALOGS__
  40.     #include <Dialogs.h>
  41. #endif
  42.  
  43.  
  44. #ifndef __CODEFRAGMENTS__
  45.     #include <CodeFragments.h>
  46. #endif
  47.  
  48.  
  49. // Application Includes
  50.  
  51. #ifndef __BAREBONES__
  52.     #include "BareBones.h"
  53. #endif
  54.  
  55. #ifndef __PROTOTYPES__
  56.     #include "Prototypes.h"
  57. #endif
  58.  
  59.  
  60.  
  61.  
  62.  
  63. StringPtr CopyPStr ( Str255    inSourceStr, StringPtr outDestStr, SInt16 inDestSize )
  64. {
  65.     SInt8 dataLen = inSourceStr[0] + 1;
  66.     
  67.     if ( dataLen > inDestSize )
  68.         dataLen = inDestSize;
  69.     BlockMoveData ( inSourceStr, outDestStr, dataLen );
  70.     outDestStr[0] = dataLen - 1;
  71.     
  72.     return outDestStr;
  73. }
  74.  
  75.  
  76.  
  77. StringPtr ConcatPStr ( Str255 ioFirstStr, Str255 inSecondStr, SInt16 inDestSize )
  78. {
  79.     SInt8 charsToCopy = inSecondStr[0];
  80.     
  81.     if ( ioFirstStr[0] + charsToCopy > inDestSize - 1 )
  82.         charsToCopy = inDestSize - 1 - ioFirstStr[0];
  83.     BlockMoveData ( inSecondStr + 1,  ioFirstStr + ioFirstStr[0] + 1, charsToCopy );
  84.     ioFirstStr[0] += charsToCopy;
  85.     
  86.     return ioFirstStr;
  87. }
  88.  
  89.  
  90.  
  91. void OSTypeToPStr ( OSType inOSType, StringPtr outString )
  92. {
  93.     BlockMoveData ( &inOSType, outString + 1, sizeof ( OSType ) );
  94.     outString[0] = sizeof ( OSType );
  95.  
  96.     return;
  97. }
  98.  
  99.  
  100.  
  101. void PStrToOSType ( StringPtr inString, OSType* outOSType )
  102. {
  103.     BlockMoveData ( inString + 1, outOSType, sizeof ( OSType ) );
  104.  
  105.     return;
  106. }
  107.  
  108.  
  109.  
  110. //
  111. // Tell the user that something went wrong
  112. //
  113. void AlertUser ( short messageCode, short errorNum, StringPtr theString )
  114. {
  115.     Str255        messageString;
  116.     Str255        numberString;
  117.     
  118.     if ( messageCode > 0 )
  119.         GetIndString ( messageString, kErrorStrings, messageCode );
  120.     else
  121.         messageString[0] = '\0';
  122.      
  123.     if ( errorNum != 0 )
  124.         NumToString ( errorNum, numberString );
  125.     else
  126.         numberString[0] = '\0';
  127.      
  128.     ParamText ( messageString, numberString, theString, (StringPtr) "\p" );
  129.     
  130.     StopAlert ( kErrorDialog, nil );
  131.     
  132.     // We need to clear the param text so it isn't used by mistake
  133.     ParamText ( (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p", (StringPtr) "\p" );
  134.     
  135.     return;
  136. }
  137.  
  138.  
  139.  
  140. void LocalToGlobalRect ( Rect* theRect )
  141. {
  142.     LocalToGlobal ( (Point*) &theRect->top );
  143.     LocalToGlobal ( (Point*) &theRect->bottom );
  144.     
  145.     return;
  146. }
  147.  
  148.  
  149.  
  150. Boolean IsMovableModal ( WindowRef theWindow )
  151. {
  152.     return (GetWVariant ( theWindow ) == movableDBoxProc);
  153. }
  154.  
  155.  
  156.  
  157. #if DEBUGGING
  158. void DebugStrNum ( Str255 str, SInt32 num )
  159. {
  160.     Str255 debug_str, tmp_str;
  161.     
  162.     BlockMoveData ( &str[0], &debug_str[0], str[0] + 1 );
  163.     
  164.     NumToString ( num , &tmp_str[0] );
  165.     debug_str[debug_str[0] + 1] = ' ';
  166.     BlockMoveData ( &tmp_str[1], &debug_str[debug_str[0] + 2], tmp_str[0] );
  167.     debug_str[0] = debug_str[0] + tmp_str[0] + 1;
  168.     DebugStr ( debug_str );
  169.     
  170.     return;
  171. }
  172. #endif
  173.  
  174.  
  175.